package com.example.netimage;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.example.netimage.data.Admins;
import com.example.netimage.service.AdminsService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class AdminListActivity extends Activity implements OnItemClickListener{
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_list);
        ListView listview=(ListView) findViewById(R.id.admin_list_view);
        try {
			List<Admins> admins=AdminsService.getJsonData();
			List<HashMap<String, Object>> data=new ArrayList<HashMap<String,Object>>();
			for(Admins admin : admins)
			{
				HashMap<String, Object> item=new HashMap<String, Object>();
				item.put("id",admin.getId());
				item.put("name", admin.getName());
				item.put("email", admin.getEmail());
				data.add(item);
			}
			SimpleAdapter adapter=new SimpleAdapter(this, data, R.layout.item, new String[] {"id","name","email"}, new int[] {R.id.id,R.id.name,R.id.email});
			listview.setAdapter(adapter);
			listview.setOnItemClickListener(this);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    }

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		System.out.println(arg1);
		TextView tv= (TextView) arg1.findViewById(R.id.name);
		String tt=tv.getText().toString();
		System.out.println(tt);
	}
}
